package edu.indiana.d2i.vmm.vm;

import java.io.InputStream;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.indiana.d2i.vmm.cloud.CloudInstanceInfo;
import edu.indiana.d2i.vmm.job.SigiriHTRCJobExeContainer;
import edu.indiana.d2i.vmm.policy.VMManagementPolicy;

/**
 * A class which should be customized by different job manager to support different 
 * software framework set up.
 */
public class BasicHTRCVMController {	
	private static final Log logger = LogFactory.getLog(BasicHTRCVMController.class);
	
	protected VMManagementPolicy policy;
	protected String publicIP;
	protected final List<CloudInstanceInfo> vmInfo;
	protected final String softwareFramework;
	protected SigiriHTRCJobExeContainer jobExeContainer = null;
	
	public BasicHTRCVMController(VMManagementPolicy policy, String softwareFramework, List<CloudInstanceInfo> vmInfo) {
		this.policy = policy;
		this.vmInfo = vmInfo; 
		this.softwareFramework = softwareFramework;
		this.jobExeContainer = new SigiriHTRCJobExeContainer();
	}
	
	public String getSoftwareFrameworkName() { return softwareFramework;}
	public List<CloudInstanceInfo> getVMInfo() { return vmInfo;}
	public VMManagementPolicy getVMPolicy() { return policy;}
	public void setVMPolicy(VMManagementPolicy policy) { this.policy = policy;}
	
	public void setupVMs() throws Exception {}
	public void uploadFile(InputStream file, String filename) throws Exception {}
	public void downloadFile(String src, String dst) throws Exception {}	
	public void runJob(String cmd, boolean sudo) throws Exception {}	
	public String getJobStatusString() { return null;}
	
	public void releaseVMs() {
		try {
			policy.releaseVMs(this);
		} catch (Exception e) {
			logger.error("Error when release VMs. " + e);
		}
		logger.info("Release VMs");
	}
}
